/*
 * WarehouseOT.java
 *
 * $Id: WarehouseOT.java,v 1.3 2009-09-28 10:21:18 mario Exp $
 */
package org.ceteca.explica.core.warehouse;

import java.io.Serializable;
import java.util.Set;

import org.ceteca.explica.core.common.BaseVO;
import org.ceteca.explica.core.partners.AddressOT;

/**
 * Store class to hold the data of a warehouse.
 * <br/>
 * Responsibilities:
 * <li>
 * 	<ul> Store of warehouse data for exchanging data among presentation, 
 * business and data access layers. </ul>
 * </li>.
 * <br/>
 * @author Mario García García <mario@ceteca.es>
 * Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <br/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <br/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class WarehouseOT extends BaseVO implements Serializable {
	/**
	 * Internal id of the warehouse.
	 */
	private long idWarehouse;
	/**
	 * Description of the warehouse.
	 */
	private String description;
	/**
	 * Phone number of the warehouse.
	 */
	private String phone;
	/**
	 * Fax number of the warehouse.
	 */
	private String fax;
	/**
	 * Contact person of the warehouse.
	 */
	private String contact;
	/**
	 * Other comments or notes about the warehouse.
	 */
	private String notes;
	/**
	 * Address of the warehouse.
	 */
	private AddressOT address;
	/**
	 * Internal id of the address (Foreign key).
	 */
	private long idAddress;

	/**
	 * Set of product lots that are in the stock of the warehouse.
	 */
	private Set lots;
	
	/**
	 * Version of the product used by Hibernate for optimistic concurrency control.
	 */
	private Integer version = new Integer(0);
	
	private static final long serialVersionUID = 10000003;
	
	
	public AddressOT getAddress() {
		return address;
	}
	public void setAddress(AddressOT address) {
		this.address = address;
	}

	public String getContact() {
		return contact;
	}
	public void setContact(String contact) {
		this.contact = contact;
	}

	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}

	public String getFax() {
		return fax;
	}
	public void setFax(String fax) {
		this.fax = fax;
	}

	public long getIdAddress() {
		return idAddress;
	}
	public void setIdAddress(long idAddress) {
		this.idAddress = idAddress;
	}

	public long getIdWarehouse() {
		return idWarehouse;
	}
	public void setIdWarehouse(long idWarehouse) {
		this.idWarehouse = idWarehouse;
	}

	public String getNotes() {
		return notes;
	}
	public void setNotes(String notes) {
		this.notes = notes;
	}

	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}

	public Set getLots() {
		return lots;
	}
	public void setLots(Set lots) {
		this.lots = lots;
	}
	/**
	 * Adds a new product lot to the stock of the warehouse.
	 * @param lot LotOT, data of the new product lot in store.
	 */
/*	public void addLot(LotOT lot) {
		this.lots.add(lot);
	}
*/
	/**
	 * Removes a lot from the stock of the warehouse.
	 * @param lot LotOT, data of the lot.
	 */
/*	public void delLot(LotOT lot) {
		if (this.lots != null && this.lots.size() > 0) {
			this.lots.remove(lot);
		}
	}
*/

	public Integer getVersion() {
		return version;
	}
	public void setVersion(Integer version) {
		this.version = version;
	}

	/**
	 * Implementation of the equals method provided by the serializable interface.
	 */
	public boolean equals(Object other) {
        if (this == other) 
        	return true;
        if ( !(other instanceof WarehouseOT) ) 
        	return false;

        final WarehouseOT w = (WarehouseOT) other;

        if ( w.getDescription() == null )
        	return this.getDescription() == null;
        else if ( !w.getDescription().equals( this.getDescription())) 
        	return false;
        
        if ( w.getAddress() == null )
        	return this.getAddress() == null;
        else if ( !w.getAddress().equals( this.getAddress()))
        	return false;

        return true;
    }

	/**
	 * Implementation of the hashCode method provided by the serializable interface.
	 */
    public int hashCode() {
        int result;
        if (this == null || this.getDescription() == null)
        	result = 0;
        else
        	result = this.getDescription().hashCode() + this.getAddress().hashCode();
        return result;
    }
    
	/**
	 * Implementation of the toString() method to show the data of the ProductOT
	 * formatted.
	 */
	public String toString() {
		StringBuffer result = new StringBuffer();
		try {
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
			result.append("\nID: ");
			result.append(this.idWarehouse);
			result.append("\nDESCRIPTION: ");
			result.append(this.description);
			result.append("\nPHONE: ");
			result.append(this.phone);
			result.append("\nFAX: ");
			result.append(this.fax);
			result.append("\nCONTACT: ");
			result.append(this.contact);
			result.append("\nADDRESS: ");
			result.append(this.address);
			result.append("\n: LOTS");
			result.append(this.lots);
			result.append("\nNOTES: ");
			result.append(this.notes);
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
		}
		catch (Exception ex) {
			System.out.println("Error formatting WarehouseOT!");
			ex.printStackTrace();
			return null;
		}
		
		return result.toString();
	}
	
	@Override
	public boolean equals(Long id) {
		return id != null && this.idWarehouse == id.longValue();
	}

	@Override
	public String getEntityId() {
		return InterfaceWarehouse.EXPLICA_ENTITY_WAREHOUSE_ID;
	}
	@Override
	public long getInternalId() {
		return this.getIdWarehouse();
	}
	@Override
	public String getInternalValue() {
		return this.description;
	}
	
	/**
	 * Returns tag Id assigned to CVS source file.
	 */
	public static String getRevision() {
		return "$Id: WarehouseOT.java,v 1.3 2009-09-28 10:21:18 mario Exp $";
	}
}
